<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Sharding</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongo.connecting.rs.html">复制集合</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongo.connecting.uds.html">Unix Domain Socket支持</a></div>
 <div class="up"><a href="mongo.connecting.html">链接服务器</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mongo.connecting.mongos" class="section">
  <h2 class="title">Sharding</h2>
  <p class="para">
   To connect to a shard cluster, specify the address of one or more
   <em>mongos</em> instances in the connection string. Multiple
   servers may be delimited by a comma.
  </p>
  <div class="example" id="mongo.connecting.mongos-example">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Using&nbsp;one&nbsp;server&nbsp;as&nbsp;the&nbsp;seed&nbsp;list<br /></span><span style="color: #0000BB">$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">(</span><span style="color: #DD0000">"mongodb://mongos1.example.com:27017"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Using&nbsp;multiple&nbsp;servers&nbsp;as&nbsp;the&nbsp;seed&nbsp;list<br /></span><span style="color: #0000BB">$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">(</span><span style="color: #DD0000">"mongodb://mongos1.example.com:27017,mongos2.example.com:27017"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <p class="para">
   Regardless of whether each shard is a stand-alone <em>mongod</em>
   server or a full replica set, the driver&#039;s connection process is the same.
   All database communication will be routed through <em>mongos</em>.
  </p>
  <p class="para">
   For more information on sharding with MongoDB, see the
   <a href="http://docs.mongodb.org/manual/sharding/" class="link external">&raquo;&nbsp;sharding documentation</a>.
  </p>
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongo.connecting.rs.html">复制集合</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongo.connecting.uds.html">Unix Domain Socket支持</a></div>
 <div class="up"><a href="mongo.connecting.html">链接服务器</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
